home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 37 / IOPROG_37.ISO / SOFT / Multilizer.exe / disk1 / data1.cab / data1 / [Group9]VCL Source Standard / ivlaseld.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-12  |  3.7 KB  |  162 lines

  1. unit IvLaSelD;
  2.  
  3. {$I IVMULTI.INC}
  4.  
  5. interface
  6.  
  7. uses
  8. {$IFDEF WIN32}
  9.   Windows,
  10. {$ELSE}
  11.   WinTypes, WinProcs,
  12. {$ENDIF}
  13.   Classes, Graphics, Forms, Controls, Buttons, StdCtrls,
  14.   IvDictio, IvMulti;
  15.  
  16. type
  17.   TIvLanguageSelectDialog = class(TForm)
  18.     ListBox: TListBox;
  19.     CancelButton: TButton;
  20.     OkButton: TButton;
  21.     HelpButton: TButton;
  22.     Translator: TIvTranslator;
  23.     procedure ListBoxDblClick(Sender: TObject);
  24.     procedure HelpButtonClick(Sender: TObject);
  25.  
  26.   protected
  27.     function GetLanguage: Integer;
  28.  
  29.   public
  30.     constructor CreateParam(
  31.       owner: TComponent;
  32.       dictionary: TIvDictionary;
  33.       const msg: String;
  34.       options: TIvLanguageDialogOptions;
  35.       helpContext: THelpContext);
  36.  
  37.     property Language: Integer read GetLanguage;
  38.   end;
  39.  
  40.   function SelectLanguage(
  41.     parent: TControl;
  42.     dictionary: TIvDictionary;
  43.     const msg: String;
  44.     options: TIvLanguageDialogOptions;
  45.     helpContext: THelpContext;
  46.     var language: Integer): Boolean;
  47.  
  48. implementation
  49.  
  50. {$R *.DFM}
  51.  
  52. function SelectLanguage(
  53.   parent: TControl;
  54.   dictionary: TIvDictionary;
  55.   const msg: String;
  56.   options: TIvLanguageDialogOptions;
  57.   helpContext: THelpContext;
  58.   var language: Integer): Boolean;
  59. var
  60.   dialog: TIvLanguageSelectDialog;
  61. begin
  62.   if not dictionary.IsOpen then
  63.     raise EIvMulti.Create(
  64.       'Dictionary is not open' +
  65.       #10#13'You must open the dictionary before you can change the language');
  66.  
  67.   Result := False;
  68.   dialog := TIvLanguageSelectDialog.CreateParam(
  69.     nil,
  70.     dictionary,
  71.     msg,
  72.     options,
  73.     helpContext);
  74.  
  75.   if not (ivloNoCenter in options) then
  76.     IvCenterControl(parent, dialog);
  77.  
  78.   if dialog.ShowModal = mrOk then
  79.   begin
  80.     language := dialog.Language;
  81.     Result := True;
  82.   end;
  83.   dialog.Free;
  84. end;
  85.  
  86. constructor TIvLanguageSelectDialog.CreateParam(
  87.   owner: TComponent;
  88.   dictionary: TIvDictionary;
  89.   const msg: String;
  90.   options: TIvLanguageDialogOptions;
  91.   helpContext: THelpContext);
  92. var
  93.   i, first: Integer;
  94.   language: TIvLanguage;
  95. begin
  96.   inherited Create(owner);
  97.  
  98.   if msg <> '' then
  99.     Caption := msg;
  100.  
  101.   Self.HelpContext := helpContext;
  102.   if helpContext = 0 then
  103.     HelpButton.Hide;
  104.  
  105.   Translator.Dictionary := dictionary;
  106.   if dictionary.Languages[0].Primary = LANG_NEUTRAL then
  107.     first := 1
  108.   else
  109.     first := 0;
  110.  
  111.   if not (ivloUseNativeLanguage in options) then
  112.     Translator.Targets.Add(TIvTargetProperty.Create('', 'Items', ivttInclude));
  113.  
  114.   for i := first to dictionary.LanguageCount - 1 do
  115.   begin
  116.     language := dictionary.Languages[i];
  117.  
  118. {$IFDEF WIN32}
  119.     if (not (ivloShowAllLanguages in options)) and
  120.       ((dictionary.CheckLevel = ivclCodePage) and
  121.        (not dictionary.IsLanguageSupportedByCodePage(language))) or
  122.       ((dictionary.CheckLevel = ivclSystem) and
  123.        (not dictionary.IsLanguageSupportedBySystem(language))) then
  124.     begin
  125.       Continue;
  126.     end;
  127. {$ENDIF}
  128.  
  129.     if ivloUseNativeLanguage in options then
  130.       ListBox.Items.AddObject(language.NativeName, TObject(i))
  131.     else
  132.       ListBox.Items.AddObject(language.EnglishName, TObject(i));
  133.   end;
  134.  
  135.   Translator.Translate;
  136.  
  137.   for i := 0 to listBox.Items.Count - 1 do
  138.     if dictionary.ActiveLanguage = Integer(listBox.Items.Objects[i]) then
  139.     begin
  140.       ListBox.ItemIndex := i;
  141.       Break;
  142.     end;
  143. end;
  144.  
  145. function TIvLanguageSelectDialog.GetLanguage: Integer;
  146. begin
  147.   Result := Integer(ListBox.Items.Objects[ListBox.ItemIndex]);
  148. end;
  149.  
  150. procedure TIvLanguageSelectDialog.ListBoxDblClick(Sender: TObject);
  151. begin
  152.   Close;
  153.   ModalResult := idOK;
  154. end;
  155.  
  156. procedure TIvLanguageSelectDialog.HelpButtonClick(Sender: TObject);
  157. begin
  158.   Application.HelpContext(HelpContext);
  159. end;
  160.  
  161. end.
  162.